package com.example.demojenkins.controller;

import com.alibaba.fastjson2.JSON;
import com.example.demojenkins.domain.DataView;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @version 1.0
 * @author: LZ
 * @description:
 * @since 2024-08-14 14:06
 */
@RestController
@RequestMapping("/api")
public class BarchartController {

    public static Map<String, Object> getDataViewList(){
        List<String> list = new ArrayList<>();
        List<String> listDate = new ArrayList<>();
        Random random = new Random();
        HashMap<String, Object> map = new HashMap<>();
        for (int i = 0; i < 7; i++) {
            Integer randomNumber = random.nextInt(90) + 10;
            String string = randomNumber.toString();
            listDate.add("短"+i);
            list.add(string);

        }
        map.put("data", list);
        map.put("date", listDate);
        return map;
    }

    @CrossOrigin
    @RequestMapping(value = "/barchart",method = RequestMethod.GET)
    public String barchart(){
        return JSON.toJSONString(getDataViewList());
    }

    @CrossOrigin
    @RequestMapping(value = "/lineChart",method = RequestMethod.GET)
    public String lineChart(){
        return JSON.toJSONString(getDataViewList());
    }

    @CrossOrigin
    @RequestMapping(value = "/donutChart",method = RequestMethod.GET)
    public String donutChart(){
        ArrayList<Object> objects = new ArrayList<>(Arrays.asList(new DataView("短袖",1),new DataView("短裤",2),new DataView("牛仔裤",3),new DataView("短裙",4),new DataView("短袜",5),new DataView("长裙",6),new DataView("衬衫",7)));
        return JSON.toJSONString(objects);
    }
}
